package com.yf.dxapp.module.app.dal.mysql.course;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yf.dxapp.module.app.controller.admin.course.vo.CoursePageReqVO;
import com.yf.dxapp.module.app.dal.dataobject.course.CourseDO;
import com.yf.dxapp.module.app.enums.app.AppBehaviorTypeEnum;
import org.apache.ibatis.annotations.Mapper;

/**
 * 课程信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface CourseMapper extends BaseMapperX<CourseDO> {

    default PageResult<CourseDO> selectPage(CoursePageReqVO reqVO) {
        LambdaQueryWrapper<CourseDO> wrapper = new LambdaQueryWrapperX<CourseDO>()
                .eqIfPresent(CourseDO::getHot, reqVO.getHot())
                .likeIfPresent(CourseDO::getTitle, reqVO.getTitle())
                .eqIfPresent(CourseDO::getCourseType, reqVO.getCourseType())
                .eqIfPresent(CourseDO::getLevelId, reqVO.getLevelId())
                .eqIfPresent(CourseDO::getShelf, reqVO.getShelf())
                .betweenIfPresent(CourseDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(CourseDO::getPublisherId, reqVO.getPublisherId())
                .eqIfPresent(CourseDO::getSelected, reqVO.getSelected())
                .eqIfPresent(CourseDO::getRecommend, reqVO.getRecommend())
                .geIfPresent(CourseDO::getLevelId, reqVO.getLevelId())
                .eqIfPresent(CourseDO::getId, reqVO.getId())
                .orderByAsc(CourseDO::getSort);
        if (reqVO.getBehaviorUserId() != null) {
            wrapper = wrapper.inSql(CourseDO::getId, "select ab.ref_id from app_behavior ab where ab.type = " + AppBehaviorTypeEnum.ClICK_COURSE.getKey() + " and ab.deleted  = 0 and ab.creator_id = " + reqVO.getBehaviorUserId());
        }
        return selectPage(reqVO, wrapper);
    }

}